package com.zhao.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhao.mapper.FollowMapper;
import com.zhao.pojo.Follow;
import com.zhao.pojo.User;
import com.zhao.pojo.comm.ChatList;
import com.zhao.service.FollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class FollowServiceImpl extends ServiceImpl<FollowMapper, Follow> implements FollowService {

    @Autowired
    FollowMapper followMapper;

    @Override
    public String isfollow(String fid, User user) {
        if (user==null){
            return "2";//未登录
        }else if(fid.equals(user.getUserId()+"")){
            return "3";//不能关注自己
        }
        Follow follow = followMapper.selectOne(new QueryWrapper<Follow>().eq("uid", user.getUserId()).eq("fid", fid));
        if (follow!=null){
            followMapper.delete(new QueryWrapper<Follow>().eq("uid", user.getUserId()).eq("fid", fid));
            return "4";//取消关注
        }
        follow=new Follow();
        follow.setUid(user.getUserId());
        follow.setFid(Integer.parseInt(fid));
        followMapper.insert(follow);
        return "1";//关注
    }

    @Override
    public List<ChatList> followList(Integer id) {
        return followMapper.followList(id);
    }
}
